package at.codebase.security;

/**
 * Provides a more secure interface for concatenating strings. This class should
 * be used everywhere in this application. It takes care of basic security
 * vulnerabilities like XSS and XSRF.
 * 
 * @author Daniel Marth <danielmarth@gmx.at>
 */
public class SecureStringBuilder {

	private StringBuilder sb = new StringBuilder();

	public SecureStringBuilder appendInsecure(String str) {
		sb.append(str);
		return this;
	}
	
	public SecureStringBuilder appendFrontInsecure(String str) {
		sb = new StringBuilder(str).append(sb);
		return this;
	}

	public SecureStringBuilder appendSecure(String str) {
		sb.append(SecurityUtils.sanatize(str));
		return this;
	}
	
	public SecureStringBuilder appendFrontSecure(String str) {
		sb = new StringBuilder(SecurityUtils.sanatize(str)).append(sb);
		return this;
	}
	
	public SecureStringBuilder append(SecureStringBuilder other) {
		sb.append(other);
		return this;
	}
	
	public SecureStringBuilder appendFront(SecureStringBuilder other) {
		sb = new StringBuilder(other.sb).append(sb);
		return this;
	}

	@Override
	public String toString() {
		return sb.toString();
	}

}
